package com.lebang.medicalInquiry.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @version V1.0
 * @author: zpc
 * @date:
 */
@SuppressWarnings("all")
public class RedisSerializerConfig {

    public static void setSerializer(RedisTemplate redisTemplate) {
        RedisSerializer jsonSerializer = new FastJsonRedisSerializer(JSON.class);
        RedisSerializer stringSerializer = new StringRedisSerializer();

        if (redisTemplate.getKeySerializer() == null) {
            redisTemplate.setKeySerializer(stringSerializer);
        }
        if (redisTemplate.getValueSerializer() == null) {
            redisTemplate.setValueSerializer(jsonSerializer);
        }
        if (redisTemplate.getHashKeySerializer() == null) {
            redisTemplate.setHashKeySerializer(stringSerializer);
        }
        if (redisTemplate.getHashValueSerializer() == null) {
            redisTemplate.setHashValueSerializer(jsonSerializer);
        }
        redisTemplate.afterPropertiesSet();
    }
}
